/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AnyadirMedio.java
 *
 * Created on 18-feb-2011, 16:17:50
 */

package AgenciaPrincipal;

import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author bernardoperea
 */
public class AnyadirMedio extends javax.swing.JFrame {

    Vector Ciudad;
    /** Creates new form AnyadirMedio */
    public AnyadirMedio(Vector Ciudades1) {
        Ciudad=Ciudades1;
        initComponents();
        rellenarCiudades();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cmbCiudades = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        cmbTransporte = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        TRecorrido = new javax.swing.JTextField();
        THorario = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        cmbCiudades.setName(""); // NOI18N
        cmbCiudades.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbCiudadesActionPerformed(evt);
            }
        });

        jLabel1.setText("Indicar Ciudad:");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Introducir Medio De Transporte:");
        jLabel2.setName("jLabel2"); // NOI18N

        cmbTransporte.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Metro", "AutoBus", "Taxi", "Tranvia", "Tren" }));
        cmbTransporte.setName("cmbTransporte"); // NOI18N

        jButton1.setText("Añadir");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        TRecorrido.setColumns(10);
        TRecorrido.setName("TRecorrido"); // NOI18N

        THorario.setColumns(10);
        THorario.setName("THorario"); // NOI18N

        jLabel3.setText("Recorrido:");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText("Horarios:");
        jLabel4.setName("jLabel4"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(cmbCiudades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1)
                            .addComponent(cmbTransporte, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(TRecorrido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel3))
                                .addGap(65, 65, 65)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(THorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addComponent(jButton1)))
                .addContainerGap(106, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(14, 14, 14)
                .addComponent(cmbCiudades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(48, 48, 48)
                .addComponent(jLabel2)
                .addGap(26, 26, 26)
                .addComponent(cmbTransporte, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TRecorrido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(THorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 136, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(21, 21, 21))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbCiudadesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbCiudadesActionPerformed
           
    }//GEN-LAST:event_cmbCiudadesActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        MediosDeTransporte m1=new MediosDeTransporte();
        ContMediosTransporte CMedio=new ContMediosTransporte();
        String medio=cmbTransporte.getSelectedItem().toString();
        String ciudad=cmbCiudades.getSelectedItem().toString();
        String pais="";
        m1.Horario=THorario.getText();
        m1.Recorrido=TRecorrido.getText();
        m1.ObtenerParametrosCiudad((Ciudades)Ciudad.get(cmbCiudades.getSelectedIndex()));
        m1.Tipo=medio;
        if(medio.compareTo("Metro")==0){
            m1.Capacidad=200;
        }

        if(medio.compareTo("AutoBus")==0){
            m1.Capacidad=50;
        }

        if(medio.compareTo("Taxi")==0){
           m1.Capacidad=4;
        }

        if(medio.compareTo("Tranvia")==0){
           m1.Capacidad=50;
        }

        if(medio.compareTo("Tren")==0){
           m1.Capacidad=400;
        }
        CMedio.AñadirMedioTransporte(m1);

        FileWriter fw;
        try {
            fw = new FileWriter("CiudadesMedios.txt",true);
            BufferedWriter bf=new BufferedWriter(fw);
            bf.write(m1.Tipo);
            bf.newLine();
            bf.write(m1.Capacidad+"");
            bf.newLine();
            bf.write(m1.Recorrido);
            bf.newLine();
            bf.write(m1.Horario);
            bf.newLine();
            bf.write(m1.NomCiudad);
            bf.newLine();
            bf.write(m1.NomPais);
            bf.newLine();

            bf.close();
            fw.close();

        } catch (IOException ex) {
            Logger.getLogger(AnyadirMedio.class.getName()).log(Level.SEVERE, null, ex);
        }
        dispose();

    

    }//GEN-LAST:event_jButton1ActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        // TODO add your handling code here:
        System.out.println("hola1");
        try {
            System.out.println("hola2");
            FormuPrincipal princi = new FormuPrincipal();
            System.out.println("hola3");
            princi.setVisible(true);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(AnyadirCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(AnyadirCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_formWindowClosing
    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField THorario;
    private javax.swing.JTextField TRecorrido;
    private javax.swing.JComboBox cmbCiudades;
    private javax.swing.JComboBox cmbTransporte;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
public void rellenarCiudades(){
     for(int i=0;i<Ciudad.size();i++)
            {
                cmbCiudades.addItem(((Ciudades)Ciudad.get(i)).Nombre);
            }

}


}
